package design_pattern.publish_subscribe;

import thread.ThreadUtils;
import threadpool.ThreadPoolFactory;

public class PublishSubscribe {

    public static void main(String[] args) {
        Broker<String> broker = new Broker<>("rabbitmq");
        Publisher<String> publisher = new Publisher<>("publisher");
        Subscriber<String> subscriber1 = new Subscriber<>("subscriber1");
        Subscriber<String> subscriber2 = new Subscriber<>("subscriber2");

        subscriber1.subscribe(broker);
        subscriber2.subscribe(broker);

        publisher.publish(broker, "西丽", true);
        publisher.publish(broker, "深圳湾", false);
        publisher.publish(broker, "前海", false);
        publisher.publish(broker, "蛇口", false);
        publisher.publish(broker, "大学城", false);
        publisher.publish(broker, "留仙洞", false);
        publisher.publish(broker, "新安", false);
        publisher.publish(broker, "宝安中心", false);
        publisher.publish(broker, "华侨城", false);

        ThreadUtils.sleep(1000);
        ThreadPoolFactory.getThreadPool().shutdown();
    }

}
